﻿@model ProductDetailsModel

@using SmartStore.Web.Models.Catalog;
@using SmartStore.Core.Domain.Orders;

@{
	if (Model.ActionItems.Count == 0)
	{
		return;
	}

	var primaryActions = Model.ActionItems.Values.Where(x => x.IsPrimary).OrderBy(x => x.Priority).ToList();
	var actions = Model.ActionItems.Values.Where(x => !x.IsPrimary).OrderBy(x => x.Priority).ToList();
}

<div class="pd-actions-container">
	@if (primaryActions.Count > 0)
	{
		<div class="pd-actions-primary">
			@foreach (var action in primaryActions)
			{
				<a href="@action.Href" class="btn btn-@action.PrimaryActionColor btn-block @action.CssClass">
					<i class="@action.IconCssClass"></i>
					<span>@action.Title</span>
				</a>
			}
		</div>
	}

	@if (actions.Count > 0)
	{
		var colClass = "col";
		if (actions.Count < 5 || actions.Count == 6)
		{
			colClass += "-" + 12 / actions.Count;
		}

		<div class="row sm-gutters pd-actions@(actions.Count > 6 ? " pd-actions-xl": "")">
			@foreach (var action in actions)
			{
				var key = action.Key;
				var isSpecial = key == "wishlist" || key == "compare";
				<div class="@colClass pd-action-item" @Html.Attr("style", "width: 20%; min-width: 20%", actions.Count == 5)>
					@if (isSpecial)
					{
						<a data-href='@action.Href' @Html.Attr("data-form-selector", "#pd-form", key == "wishlist")
						   title="@action.Tooltip"
						   href="#"
						   class="pd-action-link@(isSpecial ? " pd-action-link-special" : "") @action.CssClass"
						   rel="nofollow"
						   data-type="@key"
						   data-action="add">
							<i class="pd-action-icon @action.IconCssClass"></i>
							@if (actions.Count < 7)
							{
								<span class="pd-action-label@(actions.Count > 4 ? " fs-sm" : "")">@action.Title</span>
							}
						</a>
					}
					else
					{
						<a class="pd-action-link@(isSpecial ? " pd-action-link-special" : "") @(action.CssClass)" href="@action.Href" rel="nofollow" title="@action.Tooltip">
							<i class="pd-action-icon @action.IconCssClass"></i>
							@if (actions.Count < 7)
							{
								<span class="pd-action-label@(actions.Count > 4 ? " fs-sm" : "")">@action.Title</span>
							}
						</a>
					}
				</div>
			}
		</div>
	}
</div>

@{ Html.RenderWidget("productdetail_action_links_after"); }